import { createStore } from 'vuex'

export default createStore({
  state: {
    user:{
     isLogin:window.localStorage.getItem("token")?true:false,

   },
    editableTabsValue:'/index',
    editableTabs:[
      {
        title:'首页',
        name:'/index'
      }
    ]
  },
  getters: {
  },
  mutations: {
    setIsLogin(state, payload) {
        state.user.isLogin = payload;
    },
    setUserName(state, payload) {
           state.user.name = payload;
    },
    ADD_TABS:(state,tab)=>{
      if(state.editableTabs.findIndex(e=>e.name===tab.path)===-1){
        state.editableTabs.push({
          title:tab.name,
          name:tab.path
        })
      }
      state.editableTabsValue=tab.path
    },
    RESET_TAB:(state)=>{
      state.editableTabsValue='/index'
      state.editableTabs=[
        {
          title:'首页',
          name:'/index'
        }
      ]
    }
  },
  actions: {
  },
  modules: {
  }
})
